<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head th:replace="blogfragments :: head(~{::title})">
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0" />
		<title>博客管理</title>
		<link rel="stylesheet" href="../static/css/semantic.min.css">
		<link rel="stylesheet" type="text/css" href="../static/css/manster.css"/>
	</head>
	<body>
		<!-- 导航 -->
		<nav th:replace="blogfragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini"></nav>
		<div class="ui attached pointing menu">
			<div class="ui container">
				<div class="right menu">
					<a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
					<a href="#" th:href="@{/admin/blogs}" class="active blue item">列表</a>
				</div>
			</div>
		</div>
		
		<!-- 中间内容 -->
		<div class="m-container m-padded-tb-large" id="center">
			<div class="ui container">
				<div class="ui secondary segment form">
					<input type="hidden" name="page" />
					<div class="inline fields">
						<div class="field">
							<input type="text" name="title" placeholder="标题">
						</div>
					    <div class="field">
							<div class="ui selection dropdown">
								<input type="hidden" name="typeId">
								<i class="dropdown icon"></i>
								<div class="default text">分类</div>
								<div class="menu">
									<div th:each="type : ${types}" class="item" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
								</div>
							</div>
					  </div>
						
						<div class="field">
							<div class="ui checkbox">
								<input type="checkbox" id="recommend" name="recommend">
								<label for="recommend">推荐</label>
							</div>
						</div>
						<div class="field">
							<button type="button" id="search-btn" class="ui teal basic button"><i class="search icon"></i>搜索</button>
						</div>
					</div>
				</div>
				<div id="table-container">
					<table th:fragment="blogList" class="ui selectable compact teal table">
					<thead>
					<tr class="center aligned">
						<th>文章ID</th>
						<th>标题</th>
						<th>类型</th>
						<th>推荐</th>
						<th>发布状态</th>
						<th>更新时间</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody>
					<tr class="center aligned" th:each="blog : ${page.records}">
						<td th:text="${blog.id}">1</td>
						<td th:text="${blog.title}">java 多线程</td>
						<td th:text="${blog.type.name}">学习笔记</td>
						<td th:text="${blog.recommend} ? '是' : '否' ">推荐</td>
						<td th:text="${blog.published} ? '已发布' : '未发布' ">已发布</td>
						<td th:text="${#temporals.format(blog.updateTime, 'yyyy-MM-dd HH:mm:ss')}">2021-04-08 18:48:32</td>
						<td>
							<a href="#" th:href="@{/admin/blogs/{id}/edit(id=${blog.id})}" class="ui mini blue button">
								<i class="ui edit icon"></i>
								编辑
							</a>
							<a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui mini red button">
								<i class="ui trash alternate icon"></i>
								删除
							</a>
							<a href="#" th:href="@{/admin/blog/{id}/(id=${blog.id})}" class="ui mini button my-custom-color">
								<i class="ui eye icon "></i>
								显示原文
							</a>
						</td>
					</tr>
				  </tbody>
					<tfoot>
					<tr class="center aligned">
						<th colspan="7">
							<div class="ui small pagination menu" th:if="${page.pages} gt 1">
								<a onclick="page(this)"  th:attr="data-page=${page.current}-1" class="icon item" th:unless="${page.current le 1}">
									<i class="left chevron icon"></i>上一页
								</a>
								<th:block th:each="num : ${#numbers.sequence(1,page.pages)}">
									<a th:href="@{/admin/blogs(current=${num})}" class="item" th:text="${num}">1</a>
								</th:block>
								<a onclick="page(this)"  th:attr="data-page=${page.current}+1" class="icon item" th:unless="${page.current ge page.pages}">
									下一页<i class="right chevron icon"></i>
								</a>
							</div>
							<a href="#" th:href="@{/admin/blogs/input}" class="ui small right floated teal button">
								<i class="ui plus icon"></i>
								新增
							</a>
						</th>
					</tr>
					</tfoot>
				</table>
				<!-- 消息提示 -->
				<div class="ui success message" th:unless="${#strings.isEmpty(message)}">
					<i class="close icon"></i>
					<div class="header">提示：</div>
					<p th:text="${message}">恭喜，操作成功！</p>
				</div>

				</div>
			</div>
		</div>
		
		<!-- 底部 -->
		<footer th:replace="blogfragments :: footer" class="ui inverted vertical segment m-padded-tb-large">
		</footer>

<!--/*/<th:block th:replace="blogfragments :: script">/*/-->
		<script src="../static/js/jquery-3.3.1.js"></script>
		<script src="../static/js/semantic.min.js"></script>
		<script type="text/javascript" color="240,248,255" opacity='0.8' zIndex="-1" count="99" src="../static/js/canvas-nest.js"></script>
<!--/*/</th:block>/*/-->
		<script>
			$('.menu.toggle').click(function(){
				$('.m-item').toggleClass('m-mobile-hide');
			});
			
			$('.ui.dropdown').dropdown({
			  on : 'hover'
			});

			//消息提示关闭初始化
			$('.message .close').on('click', function () {
				$(this).closest('.message').transition('fade');
			});

			//将data-page中的数据传回给name=“page”的元素，即传到表单中
			function page(obj){
				$("[name='page']").val($(obj).data("page"));
				loaddata();
			}

			//点击搜索发送请求,将之前page中的东西清除掉
			$("#search-btn").click(function () {
				$("[name='page']").val(0);
				loaddata();
			});

			//发送请求
			function loaddata() {
				$("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
					title : $("[name='title']").val(),
					typeId : $("[name='typeId']").val(),
					recommend : $("[name='recommend']").prop('checked'),
					page : $("[name='page']").val()
				});
			}

		</script>
	</body>
</html>
